package com.czkj.hwz.decorate.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.Window;
import android.view.WindowManager;

import com.czkj.hwz.decorate.R;
import com.czkj.hwz.decorate.base.BaseActivity;
import com.czkj.hwz.decorate.FirstActivity2;


public class WelcomeActivity extends BaseActivity {
    private Handler handler = new Handler();
    SharedPreferences sp;
    private boolean isFirst;
    private boolean isFromWelcome;
    private SharedPreferences.Editor ed;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21){
            Window window = getWindow();
            //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //设置状态栏颜色
            window.setStatusBarColor(getResources().getColor(R.color.yellow));
        }
//        setContentView(R.layout.activity_welcome);解决启动时白屏
        sp=getSharedPreferences("isShowLead", MODE_PRIVATE);
        ed=sp.edit();

        firstloadjudge(); // 调用 判断第一次app启动的方法


    }
    private void firstloadjudge() {
        boolean fristload=sp.getBoolean("fristload", true);//从SharedPreferences中获取是否第一次启动   默认为true
        if (fristload) {
            toOtherActivity(GuidingActivity.class);
            finish();
            ed.putBoolean("fristload", false);//第一次启动后，将firstload 置为false 以便以后直接进入主界面不再显示欢迎界面
            ed.commit();     //提交，执行操作
        }
        else {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    goHome();
                }
            },0);
        }

    }
    protected void goHome() {
        Intent intent=new Intent();
//        intent.setClass(WelcomeActivity.this, FristActivity.class);
//        intent.setClass(WelcomeActivity.this, FirstActivity.class);
        intent.setClass(WelcomeActivity.this, FirstActivity2.class);
        startActivity(intent);
        WelcomeActivity.this.finish();
    }
}
